
interface Window {
  console: NewConsole
}

type Ttext = number | string | boolean | undefined 

interface ExtraConsole {
  primary(): void;
  success(): void;
  warning(): void;
  danger(): void;
}

type TType = keyof ExtraConsole

interface TextObj { text: any; type: TType; } 

interface NewConsole extends ExtraConsole , Console {
  capsule: (title: Ttext, info: Ttext, type?: TType) => void;
}

const enum EType {
  primary = 'primary',
  success = 'success',
  warning = 'warning',
  danger = 'danger'
}

enum COLOR_TYPE {
  primary = '#409EFF',
  success = '#67C23A',
  warning = '#E6A23C',
  danger = '#F56C6C',
  default = '#409EFF'
}

window.console = (function (originConsole) {

  if (!window.console || !originConsole) {
    originConsole = <NewConsole>{}
  }

  const typeColor = (type: TType = EType.primary) => { 
    return COLOR_TYPE[type]
  }

  const print = (textObj: TextObj) => {
    console.log(`%c${textObj.text || ''}`, `color:${typeColor(textObj.type)};`) 
  }

  originConsole.primary = function (...rest) { 
    print({ text: rest, type: EType.primary }) 
	}

	originConsole.success = function (...rest) { 
    print({ text: rest, type: EType.success }) 
	} 

	originConsole.warning = function (...rest) { 
    print({ text: rest, type: EType.warning }) 
	}

	originConsole.danger = function (...rest) { 
    print({ text: rest, type: EType.danger }) 
	}

	originConsole.capsule = function (title: Ttext, info: Ttext, type: TType = EType.primary) { 
    console.log(`%c${title}%c${info}%c`, `background:${typeColor(type)}; padding: 2px 4px; border-radius: 4px 0 0 4px; color: #fff;`, 'background:#35495E; padding: 2px 4px; border-radius: 0 4px 4px 0; color: #fff;', 'background: transparent') 
	}

  return originConsole
})(window.console)
